package com.unidue.foguing.task_B;

import java.io.IOException;

import org.apache.uima.collection.CollectionException;
import org.apache.uima.jcas.JCas;

import com.unidue.foguing.helper.ReaderHelper;
import com.unidue.foguing.types.ActualSentiment;

/**
 * This class makes the Documents available to the pipeline.
 * @author foguing
 *
 */
public class Reader_TaskB extends ReaderHelper {

	/**
	 * this method feeds the next document into the pipeline
	 */
	@Override
	public void getNext(JCas jCas) throws IOException, CollectionException {
		final String regex = "\\t";
		// split the line into 4 parts using the tab delimiter
		String[] parts = lines.get(currentLine).split(regex);
		
		// check if the line is really split in 4 parts
		if(parts.length != 4){
			throw new IOException("wrong line format: " + lines.get(currentLine));
		}
		
		// add gold standard values as annotation
		ActualSentiment actualSentiment = new ActualSentiment(jCas);
		actualSentiment.setSID(Long.parseLong(parts[0]));
		actualSentiment.setUID(Long.parseLong(parts[1]));
		actualSentiment.setNumberOfParts(parts.length);
		actualSentiment.setActualSentiment(parts[2].replaceAll("\"", "")); // some hack to remove quotation marks
		actualSentiment.addToIndexes();
		
		// add the actual tweet in the jcas
		jCas.setDocumentText(parts[3]);
		
		currentLine++;
	}

}
